

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.ico">
  <link rel="icon" href="/img/favicon.ico">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="Try not to become a man of success but rather try to become a man of value. ">
  <meta name="author" content="kinzun">
  <meta name="keywords" content>
  <meta name="description" content="什么是类具有相同属性和方法的一类事物（框架 模子）类(Class): 用来描述具有相同的属性和方法的对象的集合。它定义了该集合中每个对象所共有的属性和方法，对象是类的实例 什么是对象对象中类中一个具体的例子（具有具体的属性属性和具体的方法）​    对象就是类的实例化 类的实例 1234567调用模子得到的结果 : 对象(具体的)根据模子的规范,填上具体的值就是一个对象了python中一切皆对象">
<meta name="keywords" content="Python">
<meta property="og:type" content="article">
<meta property="og:title" content="Python 类印象">
<meta property="og:url" content="https://kinzun.github.io/2018/11/18/Python 类印象/index.html">
<meta property="og:site_name" content="kinzun">
<meta property="og:description" content="什么是类具有相同属性和方法的一类事物（框架 模子）类(Class): 用来描述具有相同的属性和方法的对象的集合。它定义了该集合中每个对象所共有的属性和方法，对象是类的实例 什么是对象对象中类中一个具体的例子（具有具体的属性属性和具体的方法）​    对象就是类的实例化 类的实例 1234567调用模子得到的结果 : 对象(具体的)根据模子的规范,填上具体的值就是一个对象了python中一切皆对象">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2018-11-30T01:49:34.511Z">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Python 类印象">
<meta name="twitter:description" content="什么是类具有相同属性和方法的一类事物（框架 模子）类(Class): 用来描述具有相同的属性和方法的对象的集合。它定义了该集合中每个对象所共有的属性和方法，对象是类的实例 什么是对象对象中类中一个具体的例子（具有具体的属性属性和具体的方法）​    对象就是类的实例化 类的实例 1234567调用模子得到的结果 : 对象(具体的)根据模子的规范,填上具体的值就是一个对象了python中一切皆对象">
  
  <title>Python 类印象 - kinzun</title>

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css">


  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css">
  <link rel="stylesheet" href="/lib/hint/hint.min.css">

  
    
    
      
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css">
    
  

  
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  


<!-- 主题依赖的图标库，不要自行修改 -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">

<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">

<link rel="stylesheet" href="/css/main.css">

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"kinzun.github.io","root":"/","version":"1.8.12","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname"}},"search_path":"/local-search.xml"};
  </script>
  <script src="/js/utils.js"></script>
  <script src="/js/color-schema.js"></script>
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>kinzun</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="Python 类印象">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2018-11-18 10:30" pubdate>
        2018年11月18日 上午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      2.6k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      8 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Python 类印象</h1>
            
            <div class="markdown-body">
              <h2 id="什么是类"><a href="#什么是类" class="headerlink" title="什么是类"></a>什么是类</h2><p>具有相同属性和方法的一类事物（框架 模子）类(Class): 用来描述具有相同的属性和方法的对象的集合。它定义了该集合中每个对象所共有的属性和方法，对象是类的实例</p>
<h2 id="什么是对象"><a href="#什么是对象" class="headerlink" title="什么是对象"></a>什么是对象</h2><p>对象中类中一个具体的例子（具有具体的属性属性和具体的方法）<br>​    对象就是类的实例化 类的实例</p>
<figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python">调用模子得到的结果 : 对象(具体的)<br>根据模子的规范,填上具体的值就是一个对象了<br><br>python中一切皆对象<br>什么是类什么是对象<br>整数是类 : <span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>是对象<br>列表是类 : [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>],[<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>]<br></code></pre></div></td></tr></table></figure>
<h2 id="什么是实例"><a href="#什么是实例" class="headerlink" title="什么是实例"></a>什么是实例</h2><p>实例完全和对象一样</p>
<h3 id="什么是实例化"><a href="#什么是实例化" class="headerlink" title="什么是实例化"></a>什么是实例化</h3><p>是由类创建对象的过程</p>
<h2 id="定义类的关键字"><a href="#定义类的关键字" class="headerlink" title="定义类的关键字"></a>定义类的关键字</h2><p><code>class</code> 类名首字母大写</p>
<h3 id="实例化的过程-：对象名-类名（）"><a href="#实例化的过程-：对象名-类名（）" class="headerlink" title="实例化的过程 ：对象名 = 类名（）"></a>实例化的过程 ：对象名 = 类名（）</h3><ol>
<li><p>创建一个属于对象的空间</p>
</li>
<li><p>执行<code>init</code> 方法，将这个空间的地址和参数传递给<strong>init</strong>方法</p>
</li>
<li><p>将对象的空间地址作为返回值，返回给对象名，（对象变量）</p>
</li>
</ol>
<h2 id="在类中可以定义的内容"><a href="#在类中可以定义的内容" class="headerlink" title="在类中可以定义的内容"></a>在类中可以定义的内容</h2><ul>
<li>静态属性 ：</li>
</ul>
<p>所有的这个类的对象 都共有的属性</p>
<ul>
<li><p>动态属性:</p>
<p>方法\ 定义在类中的函数,自带一个<code>self</code>,就是调用这个方法的对象本身</p>
</li>
</ul>
<h2 id="什么是对象的属性"><a href="#什么是对象的属性" class="headerlink" title="什么是对象的属性:"></a>什么是对象的属性:</h2><ol>
<li>存储在实例化之后 </li>
<li>创建的空间中的所有 </li>
<li>变量都是对象的属性<br>​    每一次实例化产生的空间都是独立，每一个对象都有自己的属性值</li>
</ol>
<h2 id="类名的作用"><a href="#类名的作用" class="headerlink" title="类名的作用"></a>类名的作用</h2><ul>
<li>实例化的时候 对象 = 类名（）</li>
<li>操作（调用） 静态属性 </li>
</ul>
<h2 id="对象名作用"><a href="#对象名作用" class="headerlink" title="对象名作用"></a>对象名作用</h2><ul>
<li><p>操作对象的属性</p>
</li>
<li><p>调用类中的方法（动态属性）</p>
</li>
</ul>
<p>闭包</p>
<figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python"><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span><span class="hljs-params">(name)</span>:</span><br>    dic = &#123;&#125;<br><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">bite</span><span class="hljs-params">()</span>:</span><br>        print(dic[<span class="hljs-string">'name'</span>])<br><br>    dic[<span class="hljs-string">'bite'</span>] = bite <span class="hljs-comment"># 把'bite' 函数的内存地址添加到字典</span><br>    dic[<span class="hljs-string">'name'</span>] = name<br>    <span class="hljs-keyword">return</span> dic<br><br>inn1 = func(<span class="hljs-string">'alex'</span>)<br>print(inn1)<br>inn2 = func(<span class="hljs-string">'egon'</span>)<br>inn1[<span class="hljs-string">'bite'</span>]() <span class="hljs-comment">#inn1 现在就是一个字典，bite 的值 就是一个 函数地址 加()就是调用</span><br>inn2[<span class="hljs-string">'bite'</span>]()<br><br><br><br>执行结果<br>egon<br>&#123;<span class="hljs-string">'bite'</span>: &lt;function func.&lt;locals&gt;.bite at <span class="hljs-number">0x10f61b400</span>&gt;, <span class="hljs-string">'name'</span>: <span class="hljs-string">'alex'</span>&#125;<br>alex<br>egon<br></code></pre></div></td></tr></table></figure>
<h2 id="代码示例："><a href="#代码示例：" class="headerlink" title="代码示例："></a>代码示例：</h2><figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python"><br><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span>:</span><br><br>    <span class="hljs-comment"># self 是一块内存空间</span><br>    <span class="hljs-comment"># 本身存在的内置方法</span><br>    <span class="hljs-comment"># 类名加() 直接执行 __init__ 方法</span><br><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name, gender, hp, mp, ad)</span>:</span><br>        print(<span class="hljs-string">'self&gt;&gt;&gt;&gt;'</span>, self)<br>        print(name, gender, hp, mp, ad)<br><br><br>馒头 = Person(<span class="hljs-string">'mantou'</span>, <span class="hljs-string">'man'</span>, <span class="hljs-number">10</span>, <span class="hljs-number">10</span>, <span class="hljs-number">0.1</span>)<br><br>print(<span class="hljs-string">'馒头&gt;&gt;&gt;&gt;'</span>, 馒头)<br><span class="hljs-comment">#执行结果</span><br><br>self&gt;&gt;&gt;&gt; &lt;__main__.Person object at <span class="hljs-number">0x1062a7978</span>&gt;<br>mantou man <span class="hljs-number">10</span> <span class="hljs-number">10</span> <span class="hljs-number">0.1</span><br>馒头&gt;&gt;&gt;&gt; &lt;__main__.Person object at <span class="hljs-number">0x1062a7978</span>&gt;<br><br><br><br><span class="hljs-comment"># slef 和馒头 的关系?</span><br><span class="hljs-comment"># - Person 做了什么</span><br><br><span class="hljs-comment"># 1.开辟一块内存空间</span><br><br><span class="hljs-comment"># 2.调用__init__</span><br>			<span class="hljs-comment"># 并且把开辟的空间地址 自动传递给__init__</span><br><br><span class="hljs-comment"># 3. 将self 所指向的内存空间 返回被对象 ‘馒头’ 接收了</span><br><br><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person_</span>:</span>  <span class="hljs-comment"># 类</span><br><br>    COUNTRY = <span class="hljs-string">'China'</span>  <span class="hljs-comment"># 静态属性\类属性 属于类的。 所有属于 这个类所有对象的属性</span><br><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name, gender, hp, mp, ad)</span>:</span><br>        self.name = name  <span class="hljs-comment"># 属性，属于对象的值  - 对象属性</span><br>        self.gener = gender<br>        self.hp = hp<br>        self.mp = mp<br>        self.ad = ad<br><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">attack</span><span class="hljs-params">(self)</span>:</span>  <span class="hljs-comment"># 在类中的定义的函数，就是方法|</span><br>        <span class="hljs-comment"># 动态属性 、方法</span><br>        print(self)<br><br><br>mantou = Person_(<span class="hljs-string">'mantou'</span>, <span class="hljs-string">'man'</span>, <span class="hljs-number">10</span>, <span class="hljs-number">10</span>, <span class="hljs-number">0.1</span>)  <span class="hljs-comment"># 实例化</span><br>baozi = Person_(<span class="hljs-string">'baozi'</span>, <span class="hljs-string">'man'</span>, <span class="hljs-number">100</span>, <span class="hljs-number">100</span>, <span class="hljs-number">10</span>)  <span class="hljs-comment"># 实例化</span><br><br><span class="hljs-comment"># mantou 实例\对象</span><br><br>print(mantou.name)<br>print(baozi.hp)<br><br><span class="hljs-comment"># 如何调用方法 # attack</span><br><br>baozi.attack()  <span class="hljs-comment"># 对象加方法***</span><br><br><span class="hljs-comment"># Person_.attack(mantou) 类名加方法</span><br><br><br><span class="hljs-comment"># 调用一般则是对象名加方法,也可以类名加方法</span><br><br><span class="hljs-comment"># 这两个效果都是相同的。</span><br><br><span class="hljs-comment"># 对象能够完成的事情</span><br><span class="hljs-comment"># 操作对象的属性</span><br><span class="hljs-comment"># 调用对象的方法</span><br></code></pre></div></td></tr></table></figure>
<h2 id="对象属性的值的操作"><a href="#对象属性的值的操作" class="headerlink" title="对象属性的值的操作"></a>对象属性的值的操作</h2><figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python"><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span>:</span><br>    COUNTRY = <span class="hljs-string">'China'</span>  <span class="hljs-comment"># 静态属性\类属性 属于类的。 所有属于 这个类所有对象的属性</span><br><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name, gender, hp, mp, ad)</span>:</span><br>        self.name = name  <span class="hljs-comment">#对象属性</span><br>        self.gender = gender<br>        self.hp = hp<br>        self.mp = mp<br>        self.ad = ad<br><br><br><span class="hljs-comment">#</span><br>mantou = Person_(<span class="hljs-string">'mantou'</span>, <span class="hljs-string">'man'</span>, <span class="hljs-number">10</span>, <span class="hljs-number">10</span>, <span class="hljs-number">0.1</span>)  <span class="hljs-comment"># 实例化</span><br>baozi = Person_(<span class="hljs-string">'baozi'</span>, <span class="hljs-string">'man'</span>, <span class="hljs-number">100</span>, <span class="hljs-number">100</span>, <span class="hljs-number">10</span>)  <span class="hljs-comment"># 实例化</span><br><br>print(Person_.__dict__)<br>print(mantou.__dict__)<br><br><span class="hljs-comment"># 可修改属性名</span><br>mantou.__dict__[<span class="hljs-string">'name'</span>] = <span class="hljs-string">'tu_sb'</span><br>print(mantou.__dict__)<br><br><span class="hljs-comment"># 修改属性的值</span><br><span class="hljs-comment"># mantou.hp = 9</span><br><span class="hljs-comment"># print(mantou.hp)</span><br><br><span class="hljs-comment"># 可以查看属性名</span><br>print(mantou.__dict__)<br><br><span class="hljs-comment">#尝试</span><br><span class="hljs-comment">#调用这些对象的属性(能不能修改, 能不能在实例化之后再给对象添加新的属性)</span><br><span class="hljs-comment">#查看属性值</span><br>print(alex.hp)<br><br><span class="hljs-comment">#如何给一个对象添加属性</span><br>alex.level = <span class="hljs-number">1</span><br>print(alex.level)<br><br><span class="hljs-comment">#删除属性的值</span><br><span class="hljs-keyword">del</span> alex.level<br>print(alex.level)<br></code></pre></div></td></tr></table></figure>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Python/">Python</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2018/11/20/类中的三个装饰器方法/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Python类中装饰器classmethod,staticmethod,property,</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2018/11/15/python一些小技巧/">
                        <span class="hidden-mobile">Python 一点基本技巧</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                

              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
